package tests;

import java.io.File;
import java.io.IOException;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;
import javax.sound.midi.MidiUnavailableException;
import javax.sound.midi.Soundbank;
import javax.sound.midi.Synthesizer;

import org.jfugue.Pattern;
import org.jfugue.Player;

public class TestSoundFont {

	public static void main(String[] args) {
		// Really, the hardest part is finding
		// a soundbank you like.
		Soundbank soundbank;
		try {
			soundbank = MidiSystem.getSoundbank(new File("Cello Legato.sf2"));
			// Load instruments from the soundbank
			// into the synthesizer
			Synthesizer synth = MidiSystem.getSynthesizer();
			System.out.println(synth.isSoundbankSupported(soundbank));
			synth.loadAllInstruments(soundbank);
			// Create a JFugue Player object that is attached
			// to the synthesizer with the new instrument
			//Player player1 = new Player();
			Player player2 = new Player(synth);
			// Now play your music with better results!
			Pattern pattern = new Pattern("I42 C5 D5 E5 F5 G5 A5 B5 C6");
			//player1.play(pattern);
			player2.play(pattern);
			synth.close();
		} catch (InvalidMidiDataException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (MidiUnavailableException e) {
			e.printStackTrace();
		}
	}
	
}
